package com.fivefu.core.data.controller;

import com.fivefu.base.common.utils.str.StrUtils;
import com.fivefu.base.web.controller.BaseController;
import com.fivefu.base.web.vo.ResultInfo;
import com.fivefu.core.data.services.FfskyeyeTreeService;
import com.fivefu.core.data.vo.TreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Api(tags = "树形结构")
@RestController
@RequestMapping("/tree")
public class FfskyeyeTreeController extends BaseController {

    private Logger logger = LoggerFactory.getLogger(FfskyeyeTreeController.class);

    @Autowired
    private FfskyeyeTreeService ffskyeyeTreeService;

    @ApiOperation(value = "查询树形结构",httpMethod = "POST",response = ResultInfo.class,notes = "查询树形结构")
    @ApiImplicitParam(name = "type",value = "查询类型(list,tree)",paramType = "query",required = true, dataType = "String")
    @RequestMapping(path = "/queryTreeList",method = RequestMethod.POST)
    public ResultInfo queryTreeList(String type){
        try {
            if (StrUtils.isNull(type)){
                return ResultInfo.renderError("查询类型不能为空");
            }
            List<TreeVo> list = new ArrayList<>();
            if ("list".equals(type)){
                list = ffskyeyeTreeService.queryTreeList();
            }else {
                list = ffskyeyeTreeService.queryTreeChildrenList();
            }
            return ResultInfo.renderSuccess(list);
        }catch (Exception e){
            logger.error(e.getMessage(), e);
        }
        return ResultInfo.renderError("查询树形结构失败");
    }

}
